<%@page contentType="text/html" pageEncoding="UTF-8" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<script type="text/javascript" src="<%=request.getContextPath()%>/script/json2.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/script/questionnaire/Questionnaire.js"></script>
<script type="text/javascript">
    $(function() {
        $('form').enableContentChangedConfirm();
    });

    function newversionAction(submitAction) {
        Questionnaire.actionBeforeSubmit();
        if ($("#exitpageurl").val()!=""){
        		if (IsURL($("#exitpageurl").val())==false){
        			alert("Exit Page Url is invalid!");
        			return false;
        		}
        	}
        afterSubmitRedirect("questionnaire", "newversion.html", submitAction, "submitAction");
    }

    function copyAction(submitAction) {
        Questionnaire.actionBeforeSubmit();
        if ($("#exitpageurl").val()!=""){
        		if (IsURL($("#exitpageurl").val())==false){
        			alert("Exit Page Url is invalid!");
        			return false;
        		}
        	}
        afterSubmitRedirect("questionnaire", "copy.html", submitAction, "submitAction");
    }

    function replicateAction(submitAction) {
        Questionnaire.actionBeforeSubmit();
        if ($("#exitpageurl").val()!=""){
        		if (IsURL($("#exitpageurl").val())==false){
        			alert("Exit Page Url is invalid!");
        			return false;
        		}
        	}
        afterSubmitRedirect("questionnaire", "replicate.html", submitAction, "submitAction");
    }
</script>

<!-- Menu -->
<jsp:include page="menu.jsp"/>

<!--START: Subnav -->
<div class="sub_nav">
    <ul>
        <li>
            <a href="#" onclick="navToGeneral(); return false;">
                <img src="<%= request.getContextPath()%>/images/menu/sub_general_on.gif" alt="general"/>
            </a>
        </li>
        <li>
            <a href="#" onclick="navToQs(); return false;">
                <img src="<%= request.getContextPath()%>/images/menu/sub_pages_off.gif" alt="questions"/>
            </a>
        </li>
    </ul>
</div>
<!--END: Subnav -->

<!--START: content -->
<div id="general" class="content2">
<div class="insider">
<div class="corners">
<div class="corners_top"></div>
<form:form id="questionnaire" modelAttribute="questionnaire" method="post">

<input type="hidden" id="submitAction" name="submitAction"/>
<input type="hidden" id="questionSetsData" name="questionSetsData"/>
<!-- This field is used to recover the data of the 'Pages' when the validation is failed. -->
<input type="hidden" id="questionSetsBak" name="questionSetsBak"/>
<!-- This field is used to recover the data of the Message of the 'Pages' when the validation is failed. -->
<input type="hidden" id="questionSetListMsgBak" name="questionSetListMsgBak"/>

<div class="column1">
<div class="col_l">
<table width="440" border="0" cellspacing="4"
       class="formlayout_table">
<tr>
    <th width="188">
        <label>
            ID:
        </label>
    </th>
    <td width="240">
        ${questionnaire.refId}
    </td>
</tr>
<tr>
    <th>
        <label>
            Version:
        </label>
    </th>
    <td>
        ${questionnaire.version}
    </td>
</tr>

<tr>
    <th><label>Name:</label>
    </th>
    <td class="bg_n">
        <input name="name" id="name" type="text"
               class="input3" value="${questionnaire.name}"/>
    </td>
</tr>

<tr>
    <th><label>Vocabulary Name:</label>
    </th>
    <td class="bg_n">
        <input name="vocabularyname" id="vocabularyname" type="text"
               class="input3" value="${questionnaire.vocabularyname}"/>
    </td>
</tr>

<tr>
    <th>
        <label>
            Display Title:
        </label>
    </th>
    <td class="bg_n">
        <input name="displayTitle" id="displayTitle"
               type="text" class="input3" value="${questionnaire.displayTitle}"/>
    </td>
</tr>
<tr>
    <th>
        <label>
            Description:
        </label>
    </th>
    <td class="bg_n">
        <textarea name="description" id="description" class="textarea2">${questionnaire.description}</textarea>
    </td>
</tr>
<tr>
    <th>
        <label>
            Function:
        </label>
    </th>
    <td class="bg_n">
        <select name="function.code" class="select1 functionrequired">
            <option value="" ${function.code eq "" ? "selected" : ""}>
                Please Select
            </option>
            <c:forEach var="function" items="${functions}">
                <option value="${function.code}"
                    ${function.code eq questionnaire.function.code ? "selected" : ""}>
                        ${function.code}
                </option>
            </c:forEach>
        </select>
    </td>
</tr>
<tr>
    <th>
        <label>
            Region:
        </label>
    </th>
    <td class="bg_n">
        <select name="region.code" id="Region" class="select1 regionrequired">
            <option value="" ${region.code eq "" ? "selected" : ""}>
                Please Select
            </option>
            <c:forEach var="region" items="${regions}">
                <option value="${region.code}"
                    ${region.code eq questionnaire.region.code ? "selected" : ""}>
                        ${region.code}
                </option>
            </c:forEach>
        </select>
    </td>
</tr>
<tr>
    <th>
        <label>
            Product Line:
        </label>
    </th>
    <td class="bg_n">
        <select name="productType.code" class="select1 productrequired">
            <option value="" ${productType.code eq "" ? "selected" : ""}>
                Please Select
            </option>
            <c:forEach var="productType" items="${productTypes}">
                <option value="${productType.code}"
                    ${productType.code eq questionnaire.productType.code ? "selected" : ""}>
                        ${productType.code}
                </option>
            </c:forEach>
        </select>
    </td>
</tr>
<tr>
    <th>
        <label>
            Locale:
        </label>
    </th>
    <td class="bg_n">
        <select name="locale.code" id="Locale" class="select1 localrequired">
            <option value="" ${locale.code eq "" ? "selected" : ""}>
                Please Select
            </option>
            <c:forEach var="locale" items="${locales}">
                <option value="${locale.code}"
                    ${locale.code eq questionnaire.locale.code ? "selected" : ""}>
                        ${locale.code}
                </option>
            </c:forEach>
        </select>
    </td>
</tr>
<tr>
    <th>
        <label>
            Theme:
        </label>
    </th>
    <td class="bg_n">
        <select name="theme.code" id="Theme" class="select1 themerequired">
            <option value="" ${empty questionnaire.theme.code ? "selected" : ""}>
                Please Select
            </option>
            <c:forEach var="theme" items="${themes}">
                <option value="${theme.code}"
                    ${theme.code eq questionnaire.theme.code ? "selected" : ""}>
                        ${theme.code}
                </option>
            </c:forEach>
        </select>
    </td>
</tr>
<tr>
    <th>
        <label>
            Enable Save:
        </label>
    </th>
    <td class="bg_n">
        <form:checkbox id="enableSave" path="enableSave" value="${questionnaire.enableSave}"/>
    </td>
</tr>
<tr>
    <th>
        <label>
            Summary Report:
        </label>
    </th>
    <td class="bg_n">
        <select name="summaryReport" id="SummaryReport" class="select1 summaryrequired">
            <option value="">
                Please Select
            </option>
            <option value="true" <c:if test="${questionnaire.summaryReport==true}">selected</c:if>>
                Yes
            </option>
            <option value="false" <c:if test="${questionnaire.summaryReport==false}">selected</c:if>>
                No
            </option>
        </select>
    </td>
</tr>
<tr>
    <th>
        <label>
            Decision Service Name:
        </label>
    </th>
    <td class="bg_n">
        <select name="decisionServiceName" class="select1">
            <option value="">
                Please Select
            </option>
            <c:forEach var="serviceName" items="${serviceNames}">
                <option value="${serviceName}"
                    ${serviceName eq questionnaire.decisionServiceName ? "selected" : ""}>
                        ${serviceName}
                </option>
            </c:forEach>
        </select>
    </td>
</tr>
<tr>
    <th>
        <label>
            Decision Service Version:
        </label>
    </th>
    <td class="bg_n">
        <input name="decisionServiceVersion" id="decisionServiceVersion" type="text" class="input3"
               value="${questionnaire.decisionServiceVersion}" />
    </td>
</tr>
<tr>
    <th>
        <label>
            Exit Page Url:
        </label>
    </th>
    <td class="bg_n">
        <input name="exitpageurl" id="exitpageurl" type="text" class="input3" value="${dialog.exitpageurl}"/>
    </td>
</tr>
</table>
</div>
<table width="283" border="0" cellspacing="4"
       class="formlayout_table fr">
    <tr>
        <th width="159">
            <label>
                Sibling ID:
            </label>
        </th>
        <td width="111">
            <c:if test="${OPERATION == 'replicate'}">
                ${questionnaire.sibling.refId}
            </c:if>
        </td>
    </tr>
    <tr>
        <th>
            <label>
                Sibling Version:
            </label>
        </th>
        <td>
            <c:if test="${OPERATION == 'replicate'}">
                ${questionnaire.sibling.version}
            </c:if>
        </td>
    </tr>
    <tr>
        <th>
            <label>
                Publication Status:
            </label>
        </th>
        <td>
            ${questionnaire.publicationStatus.name}
        </td>
    </tr>

    <tr>
        <th width="159">
            <label>
                Last Modified Date:
            </label>
        </th>
        <td width="111"></td>
    </tr>
    <tr>
        <th>
            <label>
                Last Modified By:
            </label>
        </th>
        <td></td>
    </tr>

    <tr>
        <th>
            <label>
                Published Date:
            </label>
        </th>
        <td></td>
    </tr>
    <tr>
        <th>
            <label>
                Published By:
            </label>
        </th>
        <td></td>
    </tr>
    <tr>
        <th>
            <label>
                Effective Date:
            </label>
        </th>
        <td></td>
    </tr>
    <tr>
        <th>
            <label>
                End Date:
            </label>
        </th>
        <td></td>
    </tr>
    <tr>
        <th>
            <label>
                Publish Notes:
            </label>
        </th>
        <td></td>
    </tr>

    <tr>
        <th>
            <label>
                Retired By:
            </label>
        </th>
        <td>
            &nbsp;
        </td>
    </tr>
    <tr>
        <th>
            <label>
                Retire Date:
            </label>
        </th>
        <td>
            &nbsp;
        </td>
    </tr>
    <tr>
        <th>
            <label>
                Retire Notes:
            </label>
        </th>
        <td>
            &nbsp;
        </td>
    </tr>
</table>
</div>
<ul class="functions1">
    <li>
        <input type="image" src="<%=request.getContextPath()%>/images/btn/functions1/btn_save.gif"
               class="btn" onclick="${OPERATION}Action('SUBMIT'); return false;"/>
    </li>
    <li>
        <input type="image" src="<%=request.getContextPath()%>/images/btn/functions1/btn_save_exit.gif"
               class="btn" onclick="${OPERATION}Action('SUBMIT_AND_EXIT'); return false;"/>
    </li>
    <li>
        <a href="#" onclick="${OPERATION}Action('SUBMIT_AND_NEW'); return false;">
            <img src="<%=request.getContextPath()%>/images/btn/functions1/btn_save_create_new.gif"
                 class="btn"/>
        </a>
    </li>
    <li>
        <a href="list.html?from=cancel&checkSearch=list">
            <img src="<%=request.getContextPath()%>/images/btn/functions1/btn_cancel.gif"
                 class="btn"/>
        </a>
    </li>
</ul>
<div class="corners_bottom"></div>
</form:form>
</div>
<div class="message">
    ${message}
    ${empty message ? "" : "<br />"}
<font color="red">
    ${errors['name.errors'][0]}
    ${empty errors['name.errors'] ? '' : '<br />'}
    
    ${errors['vocabularyname.errors'][0]}
    ${empty errors['vocabularyname.errors'] ? '' : '<br />'}

    ${errors['text.errors'][0]}
    ${empty errors['text.errors'] ? '' : '<br />'}

    ${errors['displayTitle.errors'][0]}
    ${empty errors['displayTitle.errors'] ? '' : '<br />'}

    ${errors["function.errors"]["0"]}
    ${empty errors["function.errors"]["0"] ? "" : "<br />"}

    ${errors["region.errors"]["0"]}
    ${empty errors["region.errors"]["0"] ? "" : "<br />"}

    ${errors["productType.errors"]["0"]}
    ${empty errors["productType.errors"]["0"] ? "" : "<br />"}

    ${errors["locale.errors"]["0"]}
    ${empty errors["locale.errors"]["0"] ? "" : "<br />"}

    ${errors["theme.errors"]["0"]}
    ${empty errors["theme.errors"]["0"] ? "" : "<br />"}

    ${errors["decisionServiceName.errors"]["0"]}
    ${empty errors["decisionServiceName.errors"]["0"] ? "" : "<br />"}
</font>    
</div>
</div>
</div>
<!--END: content -->

<jsp:include page="cnrPages.jsp"/>